﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using He.Web.UI;
using He.Common;
using System.Text;

namespace He.Web.manage.logistics
{
    public partial class list : Manage
    {
        public int psize = 10;
        public int page;
        public int rcount;
        public string pos_mark;
        protected void Page_Load(object sender, EventArgs e)
        {
            pos_mark = GetString("pos_mark");
            page = GetInt("page", 0);
            if (!IsPostBack)
            {
                chkLoginLevel("view" + pos_mark);

                CookieHelper.Set("LastListUrl", Request.RawUrl);    //保存最后一次访问的列表页Url

                RptBind();
            }
        }

        #region 数据绑定
        private void RptBind()
        {
            BLL.logistics bll = new BLL.logistics();
            string strWhere = "id>0";
            rptList.DataSource = bll.GetPageList(psize, page, strWhere, "id desc");
            rptList.DataBind();
            rcount = bll.GetRecordCount(strWhere);
        }
        #endregion

        #region 组合URL语句
        public string Comb_UrlTxt(string _lang, string _pos_mark)
        {
            StringBuilder strTemp = new StringBuilder();
            strTemp.AppendFormat("lang={0}&pos_mark={1}&", _lang, _pos_mark);
            return strTemp.ToString();
        }
        #endregion


        //删除
        protected void lbtnDel_Click(object sender, EventArgs e)
        {
            chkLoginLevel("del" + pos_mark);
            BLL.logistics bll = new BLL.logistics();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("Check");
                int id = int.Parse(((Label)rptList.Items[i].FindControl("lb_id")).Text);
                if (cb.Checked)
                {
                    Model.logistics model = bll.GetModel(id);
                    //删除物流进度
                    new BLL.logistics_status().Delete(model.order_number);
                    bll.Delete(id);
                }
            }
            SaveLogs("[物流管理]批量删除");
            JscriptPrint("批量删除成功啦！", Request.RawUrl, "Success");
        }

        protected void lbtnReceive_Click(object sender, EventArgs e)
        {

            chkLoginLevel("edit" + pos_mark);
            BLL.logistics bll = new BLL.logistics();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("Check");
                int id = int.Parse(((Label)rptList.Items[i].FindControl("lb_id")).Text);
                if (cb.Checked)
                {
                    bll.UpdateField(id, "status=" + (int)Enums.LogisticsStatus.已签收);
                }
            }
            SaveLogs("[物流管理]批量设置签收");
            JscriptPrint("批量设置成功啦！", Request.RawUrl, "Success");
        }
    }
}